<template>
	<view class="contont">
		<view class="registered">
			<input type="text"  placeholder="请输入电话号码" v-model="temple"/>
		</view>
		<view class="registered" style="display: flex;">
			<input type="text"  placeholder="请输入验证码" style="background-image: url(../../static/img/icon_yzm@2x.png); width: 250px;" v-model="register"/>
			<view class="yan" @click="add" v-show="Code">
				验证码
			</view>
			<view class="yan" v-show="Code==false" style="background-color: #C1C1C1;">
				{{second}}
			</view>
		</view>
		<view class="registered"  style="display: flex; border-radius: 4px 4px 0px 4px;">
			<input type="text"  placeholder="请设置密码6-20位字母,数字或符号密码" v-model="Password" style="background-image: url(../../static/img/icon_mima@3x.png);border-radius: 4px 0px 0px 4px;" />
			<view style="height: 100%;width: 36px; background:rgba(245,245,245,1);border-radius: 0px 4px 4px 0px; display: flex; align-items: center;justify-content: center;"  @click="xian">
			<image src="../../static/img/icon_zhengyan@3x.png" mode="" style="width: 16px;height: 11px;"></image>
			</view>
		</view>
		<view style="color: #888888;width: 100%;font-size: 13px;margin-left: 30px;margin-top: 30rpx;">注册即表示您同意并愿意遵守<text style="color: #042A58;"  @click="Agreement">《注册协议》</text></view>
		<button @click="reg" >立即注册</button>
	</view>
</template>

<script>
	import {ajax} from '../../api.js' 
	export default {
		data() {
			return {
				texts:0,
				Password:"",
				second:59,
				Code:true,
				temple:"",
				register:""
			}
		},
		methods: {
			// 协议
			Agreement(){
				uni.navigateTo({
					url:"../Agreement/Agreement"
				})
			},
			// 注册
		reg(){
			var that=this
			
			if(this.temple==""){
				uni.showToast({
				    title: '请输入账户',
					icon:"none"
				})
			}else if(this.register==""){
				uni.showToast({
				    title: '请输入验证码',
					icon:"none"
				})
			}else if(this.Password==""){
				uni.showToast({
				    title: '请输入密码',
					icon:"none"
				})
			}else{
				var header;
											  header = { 
								
								     'content-type': 'application/x-www-form-urlencoded', 
									  'cookie':uni.getStorageSync("send")//读取cookie
								  };
				uni.request({
				   url:"https://www.uhuoda.com/user/checkSms",
				   method:"post",
				   header:header,
				   data:{
					  smsCode:this.register,
					   mobile:this.temple
				   },
				   success(res){
					  	console.log(res)
					 if(res.data.status=="OK"){
						 			uni.request({
					url:"https://www.uhuoda.com/appdriver/regsubmit",
					data:{
						phone:that.temple,
						password:that.Password
					},
					success(res){
						console.log(res)
							uni.setStorageSync("sessionid", res.header["Set-Cookie"])
						
						if(res.data.status=="OK"){
							uni.navigateTo({
								url:"../informations/information?phone="+that.temple+"&&password="+that.Password
							})
						}else{
							uni.showToast({
							    title: res.data.message,
								icon:"none"
							})
						}
			
					}
				})
					 }else{
						 uni.showToast({
						     title: '请检查验证码',
						 	icon:"none"
						 }) 
					 }
				   },
				})
	
			}
		
		},
			// 返回登录

			// 倒计时
			add(){
				var that=this
				if(this.temple.length!=11){
					uni.showToast({
					    title: '请输入正确电话号码',
						icon:"none"
					}) 
				}else{
					uni.request({
						url:"https://www.uhuoda.com/v1/sms/regval",
						data:{
							num:this.temple,
						},
						success:function(res){
							
							uni.setStorageSync("send", res.header["Set-Cookie"])
						},
					}),
						this.Code=false
			var timer=setInterval(()=>{
				        this.second--
						if(this.second==0){
							clearInterval(timer)
							 this.second=59
							this.Code=true
						}
				   },1000)
				}   
			},
			// 眼睛
			xian(){
						var that=this
				this.text=1
				setTimeout(function(){
					that.text=0
				},3000)
			
			},
			xianed(){
				var that=this
				console.log(123)
				this.texts=1
				setTimeout(function(){
					that.texts=0
				},3000)
			}
		}
	}
</script>

<style>
.registered{
	width:345px;
	height:44px;
	border-radius:8px;
	margin-top: 15px;
}
input{
	width: 100%;
	height: 100%;
	border-radius:8px;
	background:rgba(245,245,245,1);
	background-image: url(../../static/img/icon_shouji@3x.png);
	background-repeat: no-repeat;
	background-size: 14px,18px;
	background-position: 15px 13px;
	padding-left: 40px;
	box-sizing: border-box;
	font-size: 14px;
}
.yan{
	width:85px;
	height:44px;
	background:rgba(4,42,88,1);
	border-radius:8px;
	color: #FFFFFF;
	margin-left: 10px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 14px;
}
button{
	width:345px;
	height:44px;
	background:rgba(4,42,88,1);
	border-radius:8px;
	font-size: 16px;
	margin-top: 30px;
	color: #FFFFFF;
}
 .infromeid{
	width:355px;
	height:285px;
	background:rgba(255,255,255,1);
	border-radius:8px;
	margin-top: 10px;
}
button{
	width:355px;
	height:44px;
	background:rgba(4,42,88,1);
	border-radius:8px;
	color: #FFFFFF;
}
</style>
